package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.ClientInfo;
import cn.hwadee.muying.mapper.ClientInfoMapper;
import cn.hwadee.muying.commons.base.BaseService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 客户信息 服务实现类
 * </p>
 *
 * @author Mankind
 * @since 2018-08-06
 */
@Service
public class ClientInfoService extends BaseService<ClientInfoMapper, ClientInfo> {

    @Autowired
    private ClientInfoMapper clientInfoMapper;


    public MyPage<ClientInfo> list(MyPage<ClientInfo> page, User cUser) throws Exception{
        List<ClientInfo> clientInfos = clientInfoMapper.list(page,cUser);
        page.setRecords(clientInfos);
        return page;
    }

    public ClientInfo selectByUserId(Long userId){
        List<ClientInfo> clientInfoList=clientInfoMapper.selectList(new EntityWrapper<ClientInfo>()
                        .and("user_id="+userId)
                        .and("valid=1"));
        if(clientInfoList.size()>0){
            return clientInfoList.get(0);
        }else{
            return null;
        }
    }

}
